<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./src/vue.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <parent_com></parent_com>
    </div>
    <template id="parent">
      <div>
        <p>{{JSON.stringify(user)}}</p>
        <button @click="change">setUser</button>
      </div>
    </template>
    <script>
      const parent_com = {
        template: "#parent",
        data() {
          return {
            user: {
              name: "小明",
              age: 22,
            },
          };
        },
        methods: {
          change() {
            /*
            this.user.sex = true;
            this.$forceUpdate(); // 强制当前组件渲染，它只会渲染当前组件以及内部的子组件，并不是把所有组件都重新渲染。(慎用)
            */
            // this.$set(this.user, "sex", false);
          },
        },
      };

      const vm = new Vue({
        el: "#app",
        data: {},
        components: {
          parent_com,
        },
      });
    </script>
  </body>
</html>
